<template>
  <div class="my-like">
      <div class="title">
          猜你喜欢
      </div>
      <div class="content">
         <my-cart v-for="(item,index) in list" :key="index" :itemObj="item" :sell="true"></my-cart>
      </div>
  </div>
</template>

<script>
import { ref, reactive, toRefs } from "vue";
import { getGoods } from '../api/home/index';
import myCart from './myCart.vue';
export default {
  components: { myCart },
  setup() {
    const data = reactive({
        list:[]
    })
    getGoods().then(res => {
    //    Math.random() 0-1 之间的随机数 0 - 10 的随机数 Math.random()*10
       let num = res.data.length - 4;
       let ranNum = parseInt(Math.random()*num) // 得到0-最大数（num）之间的随机整数
       data.list = res.data.splice(ranNum,4);
    //    console.log(data.list);
    })
    return{
      ...toRefs(data)
    }
  },
};
</script>
<style lang="scss" scoped>
.my-like{
  background: #fff;
  .title{
    line-height: 50px;
    text-align: center;
    font-size: 14px;
  }
  .content{
    display: flex;
    flex-wrap: wrap;
    padding: 0 10px;
    justify-content: space-between;
  }
}
</style>